//
//  HCADetailViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/2/6.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCADetailViewController.h"

#import "HCADetailView.h"

#import "HCAppointmentDetailModel.h"

#import "HCSureSuccess.h"


@interface HCADetailViewController () <HCADetailViewDelegate,HCSureSuccessDelegate> {
    HCAppointmentDetailModel *model;
    HCADetailView *vie;
    MBProgressHUD *app_hud;
    HCSureSuccess *pop;

}

@end

@implementation HCADetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.textTitle = @"门店信息";

        [WZNetWorkStatusManager show:self.centerView type:WZNetWorkStatusLoadingWithImage msg:YBKLoadingText subMsg:nil offsetY:(self.centerView.frame.size.height - YBKAdaptiveH(120))/2.0 failClickBlock:nil];
    
    self.headerView.backgroundColor = [UIColor clearColor];
    
    vie = [[HCADetailView alloc] initWithFrame:CGRectMake(0, 0, YBKAppFrame.size.width, YBKAppFrame.size.height+20)];
    vie.delegate = self;
    [self.view addSubview:vie];
    
    
    //网络数据请求
    
    self.dataRequest.delegate = self;
    [self.dataRequest postHC_StoreDetail:self.parameterObject];
    
    [self.view bringSubviewToFront:self.headerView];
    
    pop = [[HCSureSuccess alloc] initWithFrame:YBKAppFrame];
    pop.delegate = self;

    
    // Do any additional setup after loading the view.
}

-(void)didClicked {
    [self.navigationController popViewControllerAnimated:YES];
    
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    
    NSLog(@"预约详情数据返回:%@",dictionary);
    [app_hud hide:YES];
    if (aType == HC_APPOINTMENT_DEATAIL) {
        model = [[HCAppointmentDetailModel alloc] initWithDictionary:dictionary error:nil];
        
        vie.model = model;
    }else{
        if ([dictionary[@"stat"] integerValue] == 200) {
//            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"预约成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
//            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                [self.navigationController popViewControllerAnimated:YES];
//            }]];
//
//            [self presentViewController:alert animated:YES completion:NULL];
            
            [pop showAnimate];
            
        }else{
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"预约失败" message:@"预约失败" preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                //确定需要做的事情
            }]];
//            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//                //取消需要做的事情
//            }]];
            [self presentViewController:alert animated:YES completion:NULL];
        }
    }
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"预约详情请求失败");
    [app_hud hide:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)hcAppointmentClicked {
    app_hud = [MBProgressHUD showHUDAddedTo:self.centerView animated:YES];
    
    if ([ PublicFunction isNull:HCGETUSER(@"userid")]) {
        [XHToast showBottomWithText:@"请先登录，再进行预约操作" duration:2];
    }else{
        
        [self.dataRequest postHC_appointmentSure:self.parameterObject userid:HCGETUSER(@"userid") appoint_time:self.dataObject device_id:[NSString stringWithFormat:@"%@",HCGETUSER(@"deviceID")]];
        
    }

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
